#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e3+5,mod = 1e9+7;
int n,k,pw[N];
string s,t;
pair<int,int> f[N][N][2];
pair<int,int> dfs(int p,int x,int fl)
{
	if(x<0) return {0,0};
	if(p>n) return {(x==0),0};
	if(f[p][x][fl].first!=-1) return f[p][x][fl];
	int lim = 1;
	if(!fl) lim = t[p]-'0';
//	cout<<p<<' '<<x<<' '<<fl<<'\n';
	int res1 = 0,res2 = 0;
	for(int i = 0;i<=lim;i++)
	{
		int tmp,add = 0;
		if(s[p]=='L') tmp = 0;
		else tmp = 1;
		if((tmp^((k-x)&1))!=i) add = 1;
		auto now = dfs(p+1,x-add,(fl|(i<lim)));
		(res1+=now.first)%=mod;
		(res2+=now.second+i*pw[n-p]*now.first)%=mod;
	}
	return f[p][x][fl] = {res1,res2};
}
int solve()
{
	memset(f,-1,sizeof f);
	auto tmp = dfs(1,k,0);
	int res = (tmp.second+tmp.first*pw[n])%mod;
//	cout<<tmp.first<<'\n';
	memset(f,-1,sizeof f);
	for(auto &i:s)
	{
		if(i=='L') i = 'R';
		else i = 'L'; 
	}
	tmp = dfs(1,k,0);
//	cout<<tmp.first<<'\n';
	(res+=tmp.second+tmp.first*pw[n])%=mod;
	for(auto &i:s)
	{
		if(i=='L') i = 'R';
		else i = 'L'; 
	}
//	cout<<res<<'\n';
	return res;
}
signed main()
{
	freopen("lost.in","r",stdin);
	freopen("lost.out","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n>>k>>s>>t;
	pw[0] = 1; 
	for(int i = 1;i<=n;i++)
		pw[i] = pw[i-1]*2%mod;
	s = ' '+s;
	n--;
	int p = t.size()-1;
	t[p]--;
	while(t[p]=='0'-1)
	{
		t[p] = '1';
		t[p-1]--;
		p--;
	}
	int ans = 0;
//	cout<<"xx"<<t<<'\n';
	if(t[0]!='0') ans = mod-solve();
	cin>>t;
	(ans+=solve())%=mod;
	cout<<ans<<'\n';
	return 0;
}

